<?php

class NavigationHighlight {
	
	protected $location;
	
	public function handleContent($content) {
		global $request;
		$this->location = "/" . $request;
		
		if ($this->location == "/")
			return preg_replace("~<li>(\s*<a[^>]* href=\"/\")~", "<li class=\"selected\">$1", $content);
		else
			return preg_replace_callback('~<li>(\s*<a[^>]* href="([^"]{2,})")~', array($this, "replace"), $content);
	}
	
	protected function replace($matches) {
		if (strpos($this->location, $matches[2]) === 0)
			return '<li class="selected">' . $matches[1];
		else
			return $matches[0];
	}
}


?>